<%--
  Created by IntelliJ IDEA.
  User: sxs
  Date: 2020/8/8
  Time: 12:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" href="${AppPath}/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${AppPath}/css/font-awesome.min.css">
    <link rel="stylesheet" href="${AppPath}/css/main.css">
    <link rel="stylesheet" href="${AppPath}/layer/skin/default/layer.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor:pointer;
        }
        .tree-closed {
            height : 40px;
        }
        .tree-expanded {
            height : auto;
        }
    </style>
</head>

<body>
<!-- 引入头部页面 -->

<div class="container-fluid">
    <div class="row">
        <!-- 引入菜单页面 -->

        <!-- 操作区 -->
        <div>

            <div class="panel panel-default">
                <div class="panel-heading">修改角色<div style="float:right;cursor:pointer;" data-toggle="modal" data-target="#myModal"><i class="glyphicon glyphicon-question-sign"></i></div></div>
                <div class="panel-body">
                    <form id="updateRoleForm" role="form">
                        <div class="form-group">
                            <label for="roleName">修改角色名称</label>
                            <input type="text" class="form-control" id="roleName" name="roleName"  >
                            <input type="hidden" id="roleId" name="roleId" value="${roleId}">
                            <span id="roleNametip"></span>
                        </div>
                        <div class="form-group">
                            <label for="role">角色所属</label>
                            <select name="roleStatus"  id="role" class="form-control" >
                                <option selected=selected  value="2">学生</option>
                                <option  value="3">公司</option>
                                <option   value="1">员工</option>

                            </select>
                        </div>

                        <button id="updateRole"  class="btn btn-success"><i class="glyphicon glyphicon-plus"></i> 修改</button>
                        <button type="reset" class="btn btn-danger"><i class="glyphicon glyphicon-refresh"></i> 重置</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="${AppPath}/jquery/jquery-2.1.1.min.js"></script>
<script src="${AppPath}/bootstrap/js/bootstrap.min.js"></script>
<script src="${AppPath}/script/docs.min.js"></script>
<script src="${AppPath}/layer/layer.js"></script>
<script type="text/javascript" src="${AppPath}/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="${AppPath}/js/index.js"></script>
<script type="text/javascript">
    $(function () {
        var roleId=$("#roleId").val();

        $.ajax({
            url:"${AppPath}/role/findOne",
            type:"post",
            data:{"roleId":roleId},
            success:function (data) {
                if(data.result=="ok"){

                $("#roleName").val(data.role.roleName);
                $("#roleId").val(data.role.roleId);
               $("#role").val(data.role.roleStatus).prop("checked","checked");



                }else{
                    location.href="${AppPath}/search404.jsp"
                }
            }


        })
        $("#updateRole").click(function () {
            var rolename=$("#roleName").val();

            if(rolename!=null&&rolename!=""){
                $.ajax({
                    url:"${AppPath}/role/updateAjax",
                    type:"post",
                    data:$("#updateRoleForm").serialize(),
                    error:function(){
                        alert("error");
                    },
                    success:function (data) {

                        if(data.result=="ok"){

                            layer.msg("修改成功",{time:1500,icon:6},function () {


                                //关闭当前frame
                                xadmin.close();

                                // 可以对父窗口进行刷新
                                xadmin.father_reload();

                            });



                        }else{
                            layer.msg("角色名称不能重复",{time:1500,icon:5},function () {});
                        }
                    }


                })

            }else{

                layer.msg("角色名称不能为空",{time:1500,icon:5,shift:6},function () {});

            }
            return false;

        })


    });
</script>
</body>
</html>

